package com.xuexiang.xuidemo.provider;

import com.xuexiang.xui_lib.component.GridProvider;
import com.xuexiang.xuidemo.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.DirectionalLayout;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.app.Context;

import java.util.ArrayList;
import java.util.List;

public abstract class DropGridprovider extends GridProvider {

    private List<DropGridprovider.Bean> itemList = new ArrayList<>();
    private final LayoutScatter mLayoutScatter;

    protected DropGridprovider(Context context) {
        mLayoutScatter = LayoutScatter.getInstance(context);
        String[] title = getTitle();
        for (int i = 0; i < title.length; i++) {
            DropGridprovider.Bean bean = new DropGridprovider.Bean(title[i]);
            itemList.add(bean);
        }
    }

    @Override
    public int getCount() {
        return itemList.size();
    }

    @Override
    public Component getComponent(int position) {
        Component rootView = mLayoutScatter.parse(ResourceTable.Layout_dropgridprovider_view, null, false);
        Text textid = (Text) rootView.findComponentById(ResourceTable.Id_textid);
        DropGridprovider.Bean item = itemList.get(position);
        textid.setText(item.title);

       /* direlayout.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                textid.setTextColor(new Color(Color.getIntColor("#299EE3")));
            }
        });*/
        return rootView;
    }


    static class Bean {
        String title;

        public Bean(String title) {
            this.title = title;
        }
    }

    protected abstract String[] getTitle();


}
